package es.abredatos.energyes

enum FileTypeEnum {
	
	GLOBAL('T_125P'),
	THERMAL('T_127P'),
	COMMERCIAL('T_121')
	
	String code
	
	FileTypeEnum(String code){
		this.code=code
	}

	@Override
	String toString() {
		return this.code;
	}
	
	public static FileTypeEnum getFileType(String fileName) {
		if(fileName.contains(FileTypeEnum.GLOBAL.toString())){
			return FileTypeEnum.GLOBAL
		}else if(fileName.contains(FileTypeEnum.THERMAL.toString())){
			return FileTypeEnum.THERMAL
		}else if(fileName.contains(FileTypeEnum.COMMERCIAL.toString())){
			return FileTypeEnum.COMMERCIAL
		}else return null 
	}
	
	public static String[] codes() {
		return [GLOBAL.toString(),THERMAL.toString(),COMMERCIAL.toString()]
	}
	
	public static boolean isValidFileType(fileName){
		return codes().any{ fileName.contains(it) }
	}
}
